package com.example.springworkback.controller;

import com.example.springworkback.Service.InspectorsService;
import com.example.springworkfront.Service.HouseholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

@RestController
public class InspectorsController {
    @Autowired
    private InspectorsService inspectorsService;
    @Autowired
    private HouseholdService householdService;
    //检查人员登录
    @RequestMapping("/backlogin")
    public boolean backlogin(String account,String password){
        boolean login = inspectorsService.login ( account, password );
        if (login) {

            return true;
        }
        return false;
    }
    //检查人员扫码获取住户信息
    @RequestMapping("/write")
    public String write(String openid){
        String msg=householdService.checkopenid(openid);
        return msg;
    }
    //提交健康状况
    @RequestMapping("/submit")
    public String submit(String account,String temperature,String place,String date){
        System.out.println("temperature");
        System.out.println(temperature);
        System.out.println(account);
        float tem=Float.parseFloat(temperature);
        String status="";
        if (tem>37.5){ status="异常"; }
        else if (place.equals("是")){ status="待观察"; }
        else{ status="良好"; }

        Calendar cal= Calendar.getInstance();
        int h=cal.get(Calendar.HOUR_OF_DAY);
        int mi=cal.get(Calendar.MINUTE);
        int s=cal.get(Calendar.SECOND);
        String time=h+":"+mi+":"+s;
        date=date+" "+time;

        inspectorsService.add(account,tem,place,date,status);
        return status;
    }

}
